package com.maiji.cloud.controller.shopingmall;

import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.entities.login.AppUser;
import com.maiji.cloud.entities.shopingmall.CapitalMain;
import com.maiji.cloud.entities.shopingmall.DistributionComRuleLog;
import com.maiji.cloud.entities.shopingmall.DistributionLogEntity;
import com.maiji.cloud.entities.shopingmall.DistributionUserRuleLog;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.shopingmall.DbApplyExamineReqData;
import com.maiji.cloud.request.shopingmall.DbApplyInfoReqData;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseMetaResDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.login.AppUserResData;
import com.maiji.cloud.response.shopingmall.DistributionAgentApplyInfoResData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Api(tags = {"分销模块"})
@RestController
@RequestMapping("/distribution/")
public class DistributionController extends BaseController {

    /**
     * 获取分销申请信息列表
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "获取分销申请信息列表")
	@PostMapping("findAllDbApplyInfos")
	public BaseMetaResDto<List<DistributionAgentApplyInfoResData>> findAllDbApplyInfos(@RequestBody BaseDataReqDto<DbApplyInfoReqData> baseDataReqDto) {
		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/distribution/findAllDbApplyInfos", baseDataReqDto, BaseMetaResDto.class);
	}

    /**
     * 审核分销申请
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "审核分销申请")
	@PostMapping("examineDbApply")
	public BaseResDto examineDbApply(@RequestBody BaseDataReqDto<DbApplyExamineReqData> baseDataReqDto) {
		return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/distribution/examineDbApply", baseDataReqDto, BaseResDto.class);
	}

    /**
     * 获取分销用户列表
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "获取分销用户列表")
    @PostMapping("findAllDistributionUsers")
    public BaseMetaResDto<List<AppUserResData>> findAllDistributionUsers(@RequestBody BaseDataReqDto<AppUser> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/distribution/findAllDistributionUsers", baseDataReqDto, BaseMetaResDto.class);
    }

    /**
     * 编辑分销用户
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "编辑分销用户")
    @PostMapping("editDistributionUser")
    public BaseMetaResDto<List<AppUserResData>> editDistributionUser(@RequestBody BaseDataReqDto<AppUser> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/distribution/editDistributionUser", baseDataReqDto, BaseMetaResDto.class);
    }

    /**
     * 获取分销用户个人规则修改记录列表
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "获取分销用户个人规则修改记录列表")
    @PostMapping("findAllDistributionUserRuleLogs")
    public BaseDataResDto<List<DistributionUserRuleLog>> findAllDistributionUserRuleLogs(@RequestBody BaseDataReqDto<AppUser> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/distribution/findAllDistributionUserRuleLogs", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     * 获取分销流水列表
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "获取分销流水列表")
    @PostMapping("findAllDistributionLogs")
    public BaseMetaResDto<List<DistributionLogEntity>> findAllDistributionLogs(@RequestBody BaseDataReqDto<DistributionLogEntity> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/distribution/findAllDistributionLogs", baseDataReqDto, BaseMetaResDto.class);
    }

    /**
     * 获取用户的账户信息
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "获取用户的账户信息")
    @PostMapping("findCapitalMainByUserId")
    public BaseDataResDto<CapitalMain> findCapitalMainByUserId (@RequestBody BaseDataReqDto<String> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/distribution/findCapitalMainByUserId", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     * 获取分销公共规则
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "获取分销公共规则")
    @PostMapping("findDistributionComRule")
    public BaseDataResDto<DistributionComRuleLog> findDistributionComRule (@RequestBody BaseDataReqDto<String> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/distribution/findDistributionComRule", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     * 获取分销公共规则修改记录列表
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "获取分销公共规则修改记录列表")
    @PostMapping("findAllDistributionComRuleLogs")
    public BaseDataResDto<List<DistributionComRuleLog>> findAllDistributionComRuleLogs (@RequestBody BaseDataReqDto<List<Date>> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/distribution/findAllDistributionComRuleLogs", baseDataReqDto, BaseDataResDto.class);
    }

    /**
     * 修改分销公共规则
     * @param baseDataReqDto
     * @return
     */
    @ApiOperation(value = "修改分销公共规则")
    @PostMapping("editDistributionComRule")
    public BaseResDto editDistributionComRule (@RequestBody BaseDataReqDto<DistributionComRuleLog> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/distribution/editDistributionComRule", baseDataReqDto, BaseDataResDto.class);
    }


    /**
     * 获取分销用户统计
     * @return
     */
    @ApiOperation(value = "获取分销用户统计")
    @PostMapping("findDistributionUserCount")
    public BaseDataResDto<HashMap<String, Integer>> findDistributionUserCount () {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/distribution/findDistributionUserCount", null, BaseDataResDto.class);
    }

    /**
     * 获取分销资金统计
     * @return
     */
    @ApiOperation(value = "获取分销资金统计")
    @PostMapping("findDistributionCapitalCount")
    public BaseDataResDto<Map<String, Double>> findDistributionCapitalCount () {
        return restTemplate.postForObject(REST_URL_SHOPINGMALL + "/distribution/findDistributionCapitalCount", null, BaseDataResDto.class);
    }

}
